package com.founder.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.founder.dao.ClientMapper;
import com.founder.model.Client;
import com.founder.service.IClientServcie;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service("clientService")
public class ClientService implements IClientServcie {
	
	@Autowired
	private ClientMapper clientMapper;

	@Override
	public Page<Client> pageClient(int pageNum, int pageSize, String orgId, String name, String ip) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		if (name == null ) {
			name = "";
		}
		if(ip == null){
			ip = "";
		}
		name = name.trim();
		ip = ip.trim();
		if(name!=null && !"".equals(name)){
			name="%"+name+"%";	
		}
		if(ip!=null && !"".equals(ip)){
			ip="%"+ip+"%";	
		}
		
		Page<Client> page = clientMapper.pageClient(orgId, name, ip);
		return page;
	}

	@Override
	public Client getClientById(String id) {
		// TODO Auto-generated method stub
	
		return clientMapper.selectByPrimaryKey(id);
	}

	@Override
	public int addClient(Client client) {
		// TODO Auto-generated method stub
		return clientMapper.insertSelective(client);
	}

	@Override
	public int modClient(Client client) {
		// TODO Auto-generated method stub
		return clientMapper.updateByPrimaryKeySelective(client);
	}

	@Override
	public int delClientById(Client id) {
		// TODO Auto-generated method stub
		return clientMapper.delete(id);
	}

}
